package com.bweab.controll.userstbcontrol;

import com.bweab.service.api.UsersTbServiceInterface;
import com.bweab.service.impl.UsersTbServiceInterfaceImpl;
import com.bweab.util.JSONResult;
import com.bweab.util.JSONStats;
import com.bweab.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/alterUserPwd")
public class AlterUserPwd extends HttpServlet {

    //创建服务对象
    UsersTbServiceInterface usersService=new UsersTbServiceInterfaceImpl();
    //创建返回对象
    JSONResult jsonResult = new JSONResult();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取参数
        String username = req.getParameter("username");
        String userpassword = req.getParameter("userpassword");

        if(username !=null && userpassword !=null){
            int row =0;
            //调用服务层
            row= usersService.alterUserPwd(username,userpassword);
            System.out.println(row);
            //获取影响的行数
            if(row>0){
                //修改成功
                jsonResult.setStatusCode(JSONStats.ALTER_USER_PWD_OK.getStatusCode());
                jsonResult.setMessage(JSONStats.ALTER_USER_PWD_OK.getMessage());
            }else{
                jsonResult.setMessage(JSONStats.ALTER_USER_PWD_ERROR.getMessage());
                jsonResult.setStatusCode(JSONStats.ALTER_USER_PWD_ERROR.getStatusCode());
            }
            //根据行数判断
        }

        WebUtil.writeJson(resp,jsonResult);


    }
}
